<html>
<head><meta charset="utf-8"><title>can&#x27;t find crate for `std` · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/can&#x27;t.20find.20crate.20for.20.60std.60.html">can&#x27;t find crate for `std`</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="240833827"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/can%27t%20find%20crate%20for%20%60std%60/near/240833827" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andreea <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/can&#x27;t.20find.20crate.20for.20.60std.60.html#240833827">(May 31 2021 at 13:30)</a>:</h4>
<p>Hi,</p>
<p>I am trying an example from <a href="https://hackmd.io/RiztubvfT4eOk4-4nM8Y7Q?view">these slides</a>. Consider the following <code>main.rs</code> program:</p>
<div class="codehilite"><pre><span></span><code>.
#![feature(rustc_private)]
#![deny(rustc::internal)]

extern crate rustc_driver;
extern crate rustc_interface;
extern crate rustc_errors;
extern crate rustc_lint;

struct MyCallbacks;
impl rustc_driver::Callbacks for MyCallbacks {}

fn main() -&gt; Result&lt;(), rustc_errors::ErrorReported&gt; {
    let args: Vec&lt;_&gt; = std::env::args().collect();
    let mut my_cb = MyCallbacks;
    rustc_driver::RunCompiler::new(&amp;args, &amp;mut my_cb).run()
}
</code></pre></div>
<p>I created a cargo bin, with empty dependencies in <code>Cargo.toml</code>, and a test file <code>hello.rs</code>:</p>
<div class="codehilite"><pre><span></span><code>fn main() {
    println!(&quot;Hello World!&quot;);
}
</code></pre></div>
<p>The structure of files is:</p>
<div class="codehilite"><pre><span></span><code>.
├── Cargo.lock
├── Cargo.toml
├── main
├── src
│   └── main.rs
├── target
....
└── test
    ├── hello.rs
</code></pre></div>
<p>System info:</p>
<div class="codehilite"><pre><span></span><code>$ rustc --version
rustc 1.54.0-nightly (126561cb3 2021-05-24)

$cargo --version
cargo 1.54.0-nightly (070e459c2 2021-05-11)

$ rustup target list --toolchain nightly
....
x86_64-apple-darwin (installed)
</code></pre></div>
<p>Trying to run the main program I get the following results:</p>
<div class="codehilite"><pre><span></span><code>$ cargo run -- --version
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/analysis --version`
rustc 1.54.0-nightly (126561cb3 2021-05-24)

$ cargo run -- test/hello.rs
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/analysis test/hello.rs`
error[E0463]: can&#39;t find crate for `std`

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.


$ cargo run -- test/hello.rs -L /Users/andrea/.rustup/toolchains/nightly-x86_64-apple-darwin/lib
    Finished dev [unoptimized + debuginfo] target(s) in 0.00s
     Running `target/debug/analysis test/hello.rs -L /Users/andrea/.rustup/toolchains/nightly-x86_64-apple-darwin/lib`
error[E0463]: can&#39;t find crate for `core` which `std` depends on

error: aborting due to previous error

For more information about this error, try `rustc --explain E0463`.
</code></pre></div>
<p>Any idea why the <code>error[E0463]</code> errors? Running this on a MacOS. </p>
<p>Thanks,<br>
Andreea</p>



<a name="240838253"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/can%27t%20find%20crate%20for%20%60std%60/near/240838253" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/can&#x27;t.20find.20crate.20for.20.60std.60.html#240838253">(May 31 2021 at 14:13)</a>:</h4>
<p>You need to pass the <code>--sysroot</code> argument to specify the sysroot from which libstd and other sysroot crates should be loaded. You can run <code>rustc --print sysroot</code> to get the default sysroot for your rustc version. Alternatively if you are using rustup and are fine with the location of your rustup installation in the compiled binary you can use something like <a href="https://github.com/rust-lang/miri/blob/178ae8e44c5ecbe7445772a499679f62efd54a91/src/bin/miri.rs#L119-L139">https://github.com/rust-lang/miri/blob/178ae8e44c5ecbe7445772a499679f62efd54a91/src/bin/miri.rs#L119-L139</a></p>



<a name="240838259"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/can%27t%20find%20crate%20for%20%60std%60/near/240838259" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/can&#x27;t.20find.20crate.20for.20.60std.60.html#240838259">(May 31 2021 at 14:13)</a>:</h4>
<p><span class="user-mention" data-user-id="409570">@Andreea</span></p>



<a name="240838436"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/can%27t%20find%20crate%20for%20%60std%60/near/240838436" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Andreea <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/can&#x27;t.20find.20crate.20for.20.60std.60.html#240838436">(May 31 2021 at 14:15)</a>:</h4>
<p>Oh that works! Thanks a lot! (that as in using <code>--sysroot</code>)</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>